package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.rmi.server.ServerCloneException;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SysAttendanceRecord;
import com.ruoyi.system.mapper.SysAttendanceRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysTeacherScoreMapper;
import com.ruoyi.system.domain.SysTeacherScore;
import com.ruoyi.system.service.ISysTeacherScoreService;

/**
 * 家教教师评分Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-21
 */
@Service
public class SysTeacherScoreServiceImpl extends ServiceImpl<SysTeacherScoreMapper, SysTeacherScore> implements ISysTeacherScoreService
{
    @Autowired
    private SysTeacherScoreMapper sysTeacherScoreMapper;

    /**
     * 查询家教教师评分
     * 
     * @param id 家教教师评分主键
     * @return 家教教师评分
     */
    @Override
    public SysTeacherScore selectSysTeacherScoreById(Long id)
    {
        return sysTeacherScoreMapper.selectSysTeacherScoreById(id);
    }

    /**
     * 查询家教教师评分列表
     * 
     * @param sysTeacherScore 家教教师评分
     * @return 家教教师评分
     */
    @Override
    public List<SysTeacherScore> selectSysTeacherScoreList(SysTeacherScore sysTeacherScore)
    {
        return sysTeacherScoreMapper.selectSysTeacherScoreList(sysTeacherScore);
    }

    /**
     * 新增家教教师评分
     * 
     * @param sysTeacherScore 家教教师评分
     * @return 结果
     */
    @Override
    public int insertSysTeacherScore(SysTeacherScore sysTeacherScore)
    {
        if (sysTeacherScore.getTeacherScore().floatValue() > new BigDecimal("5.00").floatValue()) {
            throw new ServiceException("最高评分不能大于5.00") ;
        }
        if (sysTeacherScore.getTeacherScore().floatValue() < new BigDecimal("0.00").floatValue()) {
            throw new ServiceException("最高评分不能小于0") ;
        }
        LambdaQueryWrapper<SysTeacherScore> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysTeacherScore::getUserId ,SecurityUtils.getUserId()) ;
        wrapper.eq(SysTeacherScore::getTeacherId ,sysTeacherScore.getTeacherId()) ;
        SysTeacherScore score = this.getOne(wrapper);
        if (ObjectUtils.isNotEmpty(score)) {
            throw new ServiceException("请勿重复评价!") ;
        }
        sysTeacherScore.setCreateTime(DateUtils.getNowDate());
        sysTeacherScore.setUserId(SecurityUtils.getUserId());
        return sysTeacherScoreMapper.insertSysTeacherScore(sysTeacherScore);
    }

    /**
     * 修改家教教师评分
     * 
     * @param sysTeacherScore 家教教师评分
     * @return 结果
     */
    @Override
    public int updateSysTeacherScore(SysTeacherScore sysTeacherScore)
    {
        sysTeacherScore.setUpdateTime(DateUtils.getNowDate());
        return sysTeacherScoreMapper.updateSysTeacherScore(sysTeacherScore);
    }

    /**
     * 批量删除家教教师评分
     * 
     * @param ids 需要删除的家教教师评分主键
     * @return 结果
     */
    @Override
    public int deleteSysTeacherScoreByIds(Long[] ids)
    {
        return sysTeacherScoreMapper.deleteSysTeacherScoreByIds(ids);
    }

    /**
     * 删除家教教师评分信息
     * 
     * @param id 家教教师评分主键
     * @return 结果
     */
    @Override
    public int deleteSysTeacherScoreById(Long id)
    {
        return sysTeacherScoreMapper.deleteSysTeacherScoreById(id);
    }
}
